<?php

	$igrac = new Player($_GET['id']);
	
	// racunanje starosti igraca
	$sada = new DateTime();
	$datumR = new DateTime($igrac->datumRodjenja);
	//$starost = $sada->diff($datumR);
	$starost = $datumR;
	
	// sastavljanje stringa pozicija
	$pozicije = "";
	if (count($igrac->pozicije)) {
		foreach ($igrac->pozicije as $poz) {
			$pozicije .= $poz . ", ";
		}
		$pozicije = substr_replace($pozicije ,"",-2);
	}
	
	$timIgraca = $igrac->getTeamInfo();

?>

            <div class="threeCollumns">
                <div class="smallBox">
                	<div class="playerProfileInfo">
                    	<h3 class="playerProfileName"><?php echo $igrac->ime . " " . $igrac->prezime; ?></h3>
                    	<div class="playerProfileInfoQuestion">
                            <div class="ppQ">Jersey No:</div>
                            <div class="ppA"><?php echo $igrac->dres; ?></div>
                        </div>
                    	<div class="playerProfileInfoQuestion">
                            <div class="ppQ">Date of Birth:</div>
                            <div class="ppA"><?php echo date("d.m.Y.", strtotime($igrac->datumRodjenja)); ?></div>
                        </div>
                    	<div class="playerProfileInfoQuestion">
                            <div class="ppQ">Position:</div>
                            <div class="ppA"><?php echo $pozicije; ?></div>
                        </div>
                    	<div class="playerProfileInfoQuestion">
                            <div class="ppQ">Height:</div>
                            <div class="ppA"><?php echo $igrac->visina; ?>cm</div>
                        </div>
                    	<div class="playerProfileInfoQuestion">
                            <div class="ppQ">Weight:</div>
                            <div class="ppA"><?php echo $igrac->tezina; ?>kg</div>
                        </div>
                    	<div class="playerProfileInfoQuestion">
                            <div class="ppQ">Stronger Arm:</div>
                            <div class="ppA"><?php echo $igrac->ruka; ?></div>
                        </div>
                    </div>
                </div>

                
                <div class="smallBox">
                <img src="media/players/big/<?php echo $igrac->profilnaSlika; ?>" />
                </div>
                
                <div class="smallBox playerProfileClub">
                	<a href="team/<?php echo $timIgraca->id; ?>/<?php echo str_replace(" ", "-", $timIgraca->ime); ?>"><img src="media/teams/logo/<?php echo $timIgraca->grb; ?>" /></a>
                </div>
            </div><!-- end of #latest_news -->
            
            <div class="twoCollumns">
            	<div class="leftCollumn">

                	<div class="leftBox">
                    	<table class="tabela teamStatistics" cellpadding="0" cellspacing="0">
                        <thead>
                            <tr>
                            	<td>vs</td>
                            	<td class="statsPlayerName"></td>
                            	<td>FT</td>
                            	<td>2PT</td>
                            	<td>3PT</td>
                            	<td>PTS</td>
                            	<td>ASS</td>
                            	<td>DRB</td>
                            	<td>ORB</td>
                            	<td>BLK</td>
                            	<td>STL</td>
                            	<td>FLS</td>
                            	<td>IND</td>
                            </tr>
                        </thead>
                        <tbody>
                        
                        <?php
							$igrac->getAllStats();
							$igrac->calculateTotalStats();
						?>
                        
                        <?php
							$bru = 0;	// number of matches
							if (count($igrac->stats)) {
							foreach($igrac->stats as $utakmica) {
								$bru++;
						?>
                        
                        <?php
							$mec = new Match($utakmica->mec);
							$protivnik = NULL;
							if ($mec->domacin->id == $timIgraca->id) {
								$protivnik = $mec->gost;
							}
							else {
								$protivnik = $mec->domacin;
							}
							
						?>
                        	<tr>
                            	<td><img src="media/teams/logo/<?php echo $protivnik->grb; ?>" height="20" /></td>
                            	<td class="statsPlayerName"><a href="team/<?php echo $protivnik->id; ?>/<?php echo str_replace(" ", "-", $protivnik->ime); ?>"><?php echo $protivnik->ime; ?></a></td>
                            	<td><?php echo $utakmica->ft; ?>/<?php echo $utakmica->ft+$utakmica->mft; ?></td>
                            	<td><?php echo $utakmica->fg; ?>/<?php echo $utakmica->fg+$utakmica->mfg; ?></td>
                            	<td><?php echo $utakmica->threept; ?>/<?php echo $utakmica->threept+$utakmica->mtp; ?></td>
                            	<td><?php echo $utakmica->pts; ?></td>
                            	<td><?php echo $utakmica->ast; ?></td>
                            	<td><?php echo $utakmica->drbd; ?></td>
                            	<td><?php echo $utakmica->orbd; ?></td>
                            	<td><?php echo $utakmica->blk; ?></td>
                            	<td><?php echo $utakmica->stl; ?></td>
                            	<td><?php echo $utakmica->licne; ?></td>
                            	<td><?php echo $utakmica->BLindex; ?></td>
                            </tr>
                        <?php
                            } // foreach end
							} // if end
						?>
                        	<tr class="statsTeamTotal">
                            	<td class="statsOdd"></td>
                            	<td class="statsPlayerName">Season Total:</td>
                            	<td><?php echo $igrac->totalStats->ft; ?>/<?php echo $igrac->totalStats->ft+$igrac->totalStats->mft; ?></td>
                            	<td><?php echo $igrac->totalStats->fg; ?>/<?php echo $igrac->totalStats->fg+$igrac->totalStats->mfg; ?></td>
                            	<td><?php echo $igrac->totalStats->threept; ?>/<?php echo $igrac->totalStats->threept+$igrac->totalStats->mtp; ?></td>
                            	<td><?php echo $igrac->totalStats->pts; ?></td>
                            	<td><?php echo $igrac->totalStats->ast; ?></td>
                            	<td><?php echo $igrac->totalStats->drbd; ?></td>
                            	<td><?php echo $igrac->totalStats->orbd; ?></td>
                            	<td><?php echo $igrac->totalStats->blk; ?></td>
                            	<td><?php echo $igrac->totalStats->stl; ?></td>
                            	<td><?php echo $igrac->totalStats->licne; ?></td>
                            	<td><?php echo $igrac->totalStats->BLindex; ?></td>
                            </tr>
                            <tr class="statsTeamTotal">
                            	<td></td>
                            	<td class="statsPlayerName">Season Average:</td>
                            	<td><?php echo $bru ? round($igrac->totalStats->ft / $bru, 2) : 0; ?></td>
                            	<td><?php echo $bru ? round($igrac->totalStats->fg / $bru, 2) : 0; ?></td>
                            	<td><?php echo $bru ? round($igrac->totalStats->threept / $bru, 2) : 0; ?></td>
                            	<td><?php echo $bru ? round($igrac->totalStats->pts / $bru, 2) : 0; ?></td>
                            	<td><?php echo $bru ? round($igrac->totalStats->ast / $bru, 2) : 0; ?></td>
                            	<td><?php echo $bru ? round($igrac->totalStats->drbd / $bru, 2) : 0; ?></td>
                            	<td><?php echo $bru ? round($igrac->totalStats->orbd / $bru, 2) : 0; ?></td>
                            	<td><?php echo $bru ? round($igrac->totalStats->blk / $bru, 2) : 0; ?></td>
                            	<td><?php echo $bru ? round($igrac->totalStats->stl / $bru, 2) : 0; ?></td>
                            	<td><?php echo $bru ? round($igrac->totalStats->licne / $bru, 2) : 0; ?></td>
                            	<td><?php echo $bru ? round($igrac->totalStats->BLindex / $bru, 2) : 0; ?></td>
                            </tr>
                        </tbody>
                        </table>
                    </div>
                    <h3 class="smallBoxTitle"><a href="#">Stats</a></h3>
                    
                </div>
                
                <div class="rightCollumn">
                	<div class="smallBox">
                    	<table class="tabela" cellpadding="0" cellspacing="0">
                        <thead>
                            <tr>
                            	<td>Achievement</td>
                            	<td>#</td>
                            </tr>
                            
                        </thead>
                        <tbody>
                        
                        <?php
							$igrac->getAchievements();
							$igrac->calculateTotalAchievements();
						?>
                        	<tr>
                            	<td class="tabelaName">Top Scorer</td>
                            	<td class="tabelaPoints"><?php echo $igrac->totalAchievements->topscorer; ?></td>
                            </tr>
                        	<tr>
                            	<td class="tabelaName">Double Double</td>
                            	<td class="tabelaPoints"><?php echo $igrac->totalAchievements->doubledouble; ?></td>
                            </tr>
                        	<tr>
                            	<td class="tabelaName">Tripple Double</td>
                            	<td class="tabelaPoints"><?php echo $igrac->totalAchievements->trippledouble; ?></td>
                            </tr>
                        	<tr>
                            	<td class="tabelaName">Quadruple Double</td>
                            	<td class="tabelaPoints"><?php echo $igrac->totalAchievements->quadrupledouble; ?></td>
                            </tr>
                        	<tr>
                            	<td class="tabelaName">Game MVP</td>
                            	<td class="tabelaPoints"><?php echo $igrac->totalAchievements->gamemvp; ?></td>
                            </tr>
                        	<tr>
                            	<td class="tabelaName">Round MVP</td>
                            	<td class="tabelaPoints"><?php echo $igrac->totalAchievements->roundmvp; ?></td>
                            </tr>
                        </tbody>
                        </table>
                    </div>
                    <h3 class="smallBoxTitle"><a href="#">Records</a></h3>
                    
